package com.lineage.server.datatables.lock;

import com.lineage.server.datatables.sql.TownTable;
import com.lineage.server.datatables.storage.TownStorage;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.templates.L1Town;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class TownReading {
  private final Lock _lock = new ReentrantLock(true);
  
  private final TownStorage _storage = (TownStorage)new TownTable();
  
  private static TownReading _instance;
  
  public static TownReading get() {
    if (_instance == null)
      _instance = new TownReading(); 
    return _instance;
  }
  
  public void load() {
    this._lock.lock();
    try {
      this._storage.load();
    } finally {
      this._lock.unlock();
    } 
  }
  
  public L1Town[] getTownTableList() {
    L1Town[] tmp;
    this._lock.lock();
    try {
      tmp = this._storage.getTownTableList();
    } finally {
      this._lock.unlock();
    } 
    return tmp;
  }
  
  public L1Town getTownTable(int id) {
    L1Town tmp;
    this._lock.lock();
    try {
      tmp = this._storage.getTownTable(id);
    } finally {
      this._lock.unlock();
    } 
    return tmp;
  }
  
  public boolean isLeader(L1PcInstance pc, int town_id) {
    boolean tmp;
    this._lock.lock();
    try {
      tmp = this._storage.isLeader(pc, town_id);
    } finally {
      this._lock.unlock();
    } 
    return tmp;
  }
  
  public void addSalesMoney(int town_id, int salesMoney) {
    this._lock.lock();
    try {
      this._storage.addSalesMoney(town_id, salesMoney);
    } finally {
      this._lock.unlock();
    } 
  }
  
  public void updateTaxRate() {
    this._lock.lock();
    try {
      this._storage.updateTaxRate();
    } finally {
      this._lock.unlock();
    } 
  }
  
  public void updateSalesMoneyYesterday() {
    this._lock.lock();
    try {
      this._storage.updateSalesMoneyYesterday();
    } finally {
      this._lock.unlock();
    } 
  }
  
  public String totalContribution(int townId) {
    String tmp;
    this._lock.lock();
    try {
      tmp = this._storage.totalContribution(townId);
    } finally {
      this._lock.unlock();
    } 
    return tmp;
  }
  
  public void clearHomeTownID() {
    this._lock.lock();
    try {
      this._storage.clearHomeTownID();
    } finally {
      this._lock.unlock();
    } 
  }
  
  public int getPay(int objid) {
    this._lock.lock();
    int tmp = 0;
    try {
      this._storage.getPay(objid);
    } finally {
      this._lock.unlock();
    } 
    return 0;
  }
}
